package com.dwjm.exam.stu_list; // 请替换为实际包名

import com.dwjm.exam.pojo.Dorm;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/addDorm")
public class StudentListHanIder extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //获取请求参数(宿舍信息)
        String dormNumberStr = req.getParameter("dormNumber");
        String dormType = req.getParameter("dormType");
        String totalBedsStr = req.getParameter("totalBeds");
        String occupiedBedsStr = req.getParameter("occupiedBeds");
        String availableBedsStr = req.getParameter("availableBeds");
        String building = req.getParameter("building");
        String floor = req.getParameter("floor");
        String manager = req.getParameter("manager");

        Dorm dorm = new Dorm(null,
                Integer.parseInt(dormNumberStr),
                dormType,
                Integer.parseInt(totalBedsStr),
                Integer.parseInt(occupiedBedsStr),
                Integer.parseInt(availableBedsStr),
                building,
                floor,
                manager);
        StudentListDao dormDao = new StudentListDaoImpl();
        int res = dormDao.addDorm(dorm);
        if (res == 1) {
            resp.getWriter().write("Success");
        } else {
            resp.getWriter().write("Fail");
        }
    }

}